package cn.com.test.common.listener;

import javax.servlet.http.*;

public class SessionListener implements HttpSessionListener, HttpSessionActivationListener,
		HttpSessionBindingListener, HttpSessionAttributeListener {
	/**
	 * @Description: session变为有效状态
	 * @author chenwb
	 * @date 2019/12/17 17:02
	 * @param httpSessionEvent
	 * @return 输出参数
	 */
	@Override
	public void sessionWillPassivate(HttpSessionEvent httpSessionEvent) {
		System.out.println("session已经有效,sessionId:" + httpSessionEvent.getSession().getId());
	}

	/**
	 * @Description: session变为失效状态
	 * @author chenwb
	 * @date 2019/12/17 17:03
	 * @param httpSessionEvent
	 * @return 输出参数
	 */
	@Override
	public void sessionDidActivate(HttpSessionEvent httpSessionEvent) {
		System.out.println("session已经失效,sessionId:" + httpSessionEvent.getSession().getId());
	}

	/**
	 * @Description: 有对象加入session时触发
	 * @author chenwb
	 * @date 2019/12/17 17:04
	 * @param httpSessionBindingEvent
	 * @return 输出参数
	 */
	@Override
	public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {
		System.out.println("有对象加入session,属性名： " + httpSessionBindingEvent.getName() + " 属性值：" + httpSessionBindingEvent.getValue());
	}

	/**
	 * @Description: 有对象移出session时触发
	 * @author chenwb
	 * @date 2019/12/17 17:04
	 * @param httpSessionBindingEvent
	 * @return 输出参数
	 */
	@Override
	public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {
		System.out.println("有对象移出session 属性名：" + httpSessionBindingEvent.getName() + " 属性值：" + httpSessionBindingEvent.getValue());
	}

	/**
	 * @Description: session中有对象替换时触发
	 * @author chenwb
	 * @date 2019/12/17 17:04
	 * @param httpSessionBindingEvent
	 * @return 输出参数
	 */
	@Override
	public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {
		System.out.println("session中有对象替换 属性名： " + httpSessionBindingEvent.getName() + " 属性值：" + httpSessionBindingEvent.getValue());
	}

	@Override
	public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {
		System.out.println("有对象加入session，valueBound自动调用 属性名： " + httpSessionBindingEvent.getName() + " 属性值：" + httpSessionBindingEvent.getValue());
	}

	@Override
	public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
		System.out.println("有对象移出session，valueUnbound自动调用 属性名： " + httpSessionBindingEvent.getName() + " 属性值：" + httpSessionBindingEvent.getValue());
	}

	@Override
	public void sessionCreated(HttpSessionEvent httpSessionEvent) {
		System.out.println("session创建了,sessionId: " + httpSessionEvent.getSession().getId());
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
		System.out.println("session销毁了,sessionId:  " + httpSessionEvent.getSession().getId());
	}
}
